#include "LobbyScene.h"
#include "GameScene.h"
#include "WorldScene.h"
#include "InfoScene.h"
#include "ShopScene.h"
#include "ConfigScene.h"

USING_NS_CC;

CCScene* LobbyScene::scene()
{
	// 'scene' is an autorelease object
	CCScene *scene = CCScene::create();

	// 'layer' is an autorelease object
	LobbyScene *layer = LobbyScene::create();

	// add layer as a child to scene
	scene->addChild(layer);

	// return the scene
	return scene;
}

// on "init" you need to initialize your instance
bool LobbyScene::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayer::init() )
	{
		return false;
	}

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();


	CCLabelTTF* lableTTF = CCLabelTTF::create("입장", "Arial", 50);
	CCMenuItemLabel* menuStart = CCMenuItemLabel::create(lableTTF, this, menu_selector(LobbyScene::enterSceneCallback));
    menuStart->setTag(0);
	menuStart->setPosition(ccp(winSize.width - lableTTF->getContentSize().width - 50,600));

	lableTTF = CCLabelTTF::create("상점", "Arial", 50);
	CCMenuItemLabel* menuShop = CCMenuItemLabel::create(lableTTF, this, menu_selector(LobbyScene::enterSceneCallback));
    menuShop->setTag(1);
	menuShop->setPosition(ccp(winSize.width - lableTTF->getContentSize().width - 50,500));

	lableTTF = CCLabelTTF::create("설정", "Arial", 50);
	CCMenuItemLabel* menuConfig = CCMenuItemLabel::create(lableTTF, this, menu_selector(LobbyScene::enterSceneCallback));
    menuConfig->setTag(2);
	menuConfig->setPosition(ccp(winSize.width - lableTTF->getContentSize().width - 50,400));

	lableTTF = CCLabelTTF::create("정보", "Arial", 50);
	CCMenuItemLabel* menuInfo = CCMenuItemLabel::create(lableTTF, this, menu_selector(LobbyScene::enterSceneCallback));
    menuInfo->setTag(3);
	menuInfo->setPosition(ccp(winSize.width - lableTTF->getContentSize().width - 50,300));

	lableTTF = CCLabelTTF::create("종료", "Arial", 50);
	CCMenuItemLabel* menuExit = CCMenuItemLabel::create(lableTTF, this, menu_selector(LobbyScene::enterSceneCallback));
    menuExit->setTag(4);
	menuExit->setPosition(ccp(winSize.width - lableTTF->getContentSize().width - 50,200));

	// create menu, it's an autorelease object
	CCMenu* pMenu = CCMenu::create(menuStart, menuShop, menuConfig, menuInfo, menuExit, NULL);
	pMenu->setPosition(CCPointZero);
	this->addChild(pMenu, 1);

	CCLabelTTF* pLabel = CCLabelTTF::create("Lobby", "Arial", 24);

	// position the label on the center of the screen
	pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
			origin.y + visibleSize.height - pLabel->getContentSize().height));

	// add the label as a child to this layer
	this->addChild(pLabel, 1);

	// add "HelloWorld" splash screen"
	CCSprite* pSprite = CCSprite::create("HelloWorld.png");

	// position the sprite on the center of the screen
	pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

	// add the sprite as a child to this layer
	this->addChild(pSprite, 0);

	return true;
}


void LobbyScene::enterSceneCallback(CCObject* pSender)
{
    CCScene* scene = NULL;
    CCNode* item = dynamic_cast<CCNode*>(pSender);
    
    switch(item->getTag())
    {
        case 0:
            scene = GameScene::scene();
            break;
            
        case 1:
            scene = ShopScene::scene();
            break;
            
        case 2:
            scene = ConfigScene::scene();
            break;
            
        case 3:
            scene = InfoScene::scene();
            break;
            
        case 4:
            scene = WorldScene::scene();
            break;
    }
    
	CCDirector::sharedDirector()->replaceScene(CCTransitionJumpZoom::create(1.0, scene));
}

